package com.base.servlet;

import java.io.IOException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.base.util.DateUtil;
import com.homework.entity.Homewokmaster;
import com.homework.service.HomeWorkService;

/**
 * Servlet implementation class AddHomeWorkServlet
 */
public class AddHomeWorkServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddHomeWorkServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		HomeWorkService hs=new HomeWorkService();
		Homewokmaster hmaster=new Homewokmaster();
		String content=request.getParameter("content");
		hmaster.setContent(content);
		
		hmaster.setTitle(request.getParameter("title"));
		
		hmaster.setType(request.getParameter("type"));
		
		String opendatestr=request.getParameter("openDate");
		
		Date t1=DateUtil.tranceToDate(opendatestr);
		
		hmaster.setOpen_date(DateUtil.tranceToSqlDate(t1));
		
		if(hs.addHomeWork(hmaster)){
			request.setAttribute("rs", "作业保存成功");
		};
		//解决中文乱码问题
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		
		request.getRequestDispatcher("index4.jsp").forward(request,response);
//		response.sendRedirect("index4.jsp");
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
